<style scoped>
    .el-dialog .inputWidth100 .el-input{width:100%;}
    /* 新建的弹窗 */
    .el-dialog.el-dialog--small{width:36%;}
    .el-dialog .el-dialog__body{padding-bottom:0;}
    /*.el-dialog .el-input{width:66%;}*/
    .el-dialog .el-dialog__body .el-form-item:last-of-type{margin-bottom:0;}
    .el-dialog .el-form-item__label{text-align: left;}
    .el-form-item__error{left: 20%}
    /* 所属法人、公司名称 */
    /*#addMask .el-dialog .name-input{margin-bottom:20px;}*/
    #addMask .el-dialog .name-input .el-select{width:100%;}
    #addMask .el-dialog .name-input .el-form-item__error{top:95%;left:23%;}
    /* 法人code */
    #addMask .code-input{margin-bottom:10px;}

    

    /* 修改业务合作人员 */
    #editMask .el-dialog .el-input.el-input--small{width:100%;}
    #editMask .el-dialog .el-select{width:100%;}
    .el-select-dropdown{max-width:408px;}
</style>
<template> 
	<div class="business-partner-page">
        <el-form :inline="true" :model="bpForm" class="demo-form-inline" style="border-bottom:1px solid #ccc;">
            <!--人员名称-->
            <el-form-item :label="nowLangue.personName" class="selectMB10"  >
                <el-input size="mini" type="text" v-model="bpForm.name" auto-complete="off" :placeholder="nowLangue.pleaseImport+nowLangue.personName"></el-input>
            </el-form-item>
            <!--登录账号-->
            <el-form-item :label="nowLangue.loginAccount" class="selectMB10" >
                <el-input size="mini" type="text" v-model="bpForm.login" auto-complete="off" :placeholder="nowLangue.pleaseImport+nowLangue.loginAccount"></el-input>
            </el-form-item>
            <!--当前状态-->
            <el-form-item :label="nowLangue.currStatus" class="selectMB10" >
                <el-select size="mini" clearable v-model="bpForm.state">
                    <el-option v-for="(stateOption,index) in bpForm.stateOptions" :key="index" :label="stateOption.label" :value="stateOption.value"  :placeholder="nowLangue.pleaseSelect"></el-option>
                </el-select>
            </el-form-item>
            <!--供应商名称-->
            <el-form-item :label="nowLangue.supplierName" class="selectMB10" >
                <el-input size="mini" type="text" v-model="bpForm.vendorName" auto-complete="off" :placeholder="nowLangue.pleaseImport+nowLangue.supplierName"></el-input>
            </el-form-item>
            <!--供应商代码-->
            <el-form-item :label="nowLangue.supplierNo" class="selectMB10" >
                <el-input size="mini" type="text" v-model="bpForm.vendorCode" auto-complete="off" :placeholder="nowLangue.pleaseImport+nowLangue.supplierNo"></el-input>
            </el-form-item>
            <el-form-item  class="selectMB10">
                <!--查询-->
                <el-button class="bolder outsideBtnBS selectAll" :disabled="selectDisabled" size="mini" type="danger" @click="handleQuery(pageIndex,pageSize)" v-text="nowLangue.query"></el-button>
            </el-form-item>
        </el-form>

        <!--表格-->
        <!--供应商人员列表：-->
        <label class="default-label" v-text="nowLangue.listOfSuppliers"></label>
        <!--新增人员-->
        <el-button class="bolder outsideBtnBS" v-if="powerFlag1" size="mini" @click="showAddStaffForm()" type="danger" v-text="nowLangue.create"></el-button>

        <el-table :data="bpList" border style="width: 100%;" v-loading.body="loading" element-loading-text="拼命加载中">
            <!--序-->
            <el-table-column type="index" header-align="center" align="center" :label="nowLangue.sequence"  width="40"></el-table-column>
            <!--操作-->
            <el-table-column prop="enabled" :label="nowLangue.operate" header-align="center" align="center" width="140" v-if="powerFlag1 || powerFlag2">
                <template scope="scope">
                    <!--禁用-->
                    <button class="operationItem bolder" v-if="scope.row.enabled && powerFlag1" @click="handleDisable(scope.$index, scope.row)" v-text="nowLangue.forbidden" :disabled="statusDisabled"></button>
                    <!--启用-->
                    <button class="operationItem bolder" v-else-if="!scope.row.enabled && powerFlag1" @click="handleOpen(scope.$index, scope.row)" v-text="nowLangue.enable" :disabled="statusDisabled"></button>
                    <!--修改-->
                    <button class="operationItem bolder" v-if="!scope.row.enabled && powerFlag1" @click="shoEditStaffForm(scope.row)" v-text="nowLangue.update"></button>
                    <!--修改-->
                    <button class="operationItem disabled bolder" v-else-if="scope.row.enabled && powerFlag1" v-text="nowLangue.update"></button>
                    <!--重置密码-->
                    <button class="operationItem bolder" v-if="scope.row.enabled && powerFlag2" @click="resetPassword(scope.row)" v-text="nowLangue.resetPassword"></button>
                    <!--重置密码-->
                    <button class="operationItem disabled bolder" v-else-if="!scope.row.enabled && powerFlag2" v-text="nowLangue.resetPassword"></button>
                </template>
            </el-table-column>
            <!--法人名称-->
            <el-table-column prop="personName" :label="nowLangue.personName" header-align="center" width="100" show-overflow-tooltip></el-table-column>
            <!--登录账户-->
            <el-table-column prop="userName" :label="nowLangue.loginAccount" header-align="center" width="100" show-overflow-tooltip></el-table-column>
            <!--供应商名称-->
            <el-table-column prop="providerName" :label="nowLangue.supplierName" header-align="center" show-overflow-tooltip></el-table-column>
            <!--供应商代码-->
            <el-table-column prop="providerCode" :label="nowLangue.supplierNo" header-align="center" width="120" show-overflow-tooltip></el-table-column>
            <!--邮箱-->
            <el-table-column prop="email" :label="nowLangue.email" header-align="center" width="140" show-overflow-tooltip></el-table-column>
            <!--联系电话-->
            <el-table-column prop="telephone" :label="nowLangue.contactNumber" header-align="center" width="140" show-overflow-tooltip></el-table-column>
            <!--当前状态-->
            <el-table-column prop="status" :label="nowLangue.currStatus" header-align="center" align="center" width="80" show-overflow-tooltip></el-table-column>
        </el-table>
		<!--分页-->
		<el-pagination v-if="isPaging" @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="pageIndex" :page-sizes="[10, 20, 30, 40]" :page-size="pageSize" layout="total, sizes, prev, pager, next, jumper" :page-count="totalPage" :total="totalNumber"></el-pagination>

        <!--新增业务合作人员-->
        <el-dialog :title="nowLangue.create+nowLangue.businessCooperationPersonnel" :visible.sync="dialogbpStaffAddFormVisible" id="addMask" size="small" :lock-scroll="false">
            <el-form :model="bpStaffAddForm" ref="bpStaffAddForm"  :inline="true"  class="demo-form-inline label-minW110">
                <!--姓　　名-->
	            <el-form-item :label="nowLangue.fullName" prop="personName"  :rules="[{ required: true, message: nowLangue.required},{ min: 1, message: nowLangue.greaterThan1},{ max: 20, message: nowLangue.lessThan20}]">
	                <el-input size="mini" v-model.trim="bpStaffAddForm.personName" auto-complete="off" :placeholder="nowLangue.pleaseImport+nowLangue.fullName"></el-input>
	            </el-form-item>
                <!--登录账户-->
	            <el-form-item :label="nowLangue.loginAccount" prop="userName" :rules="[{ required: true, message: nowLangue.required},{ min: 1, message: nowLangue.greaterThan1},{ max: 20, message: nowLangue.lessThan20},{ validator: checkUserName, trigger: 'blur'}]">
	                <el-input size="mini" v-model.trim="bpStaffAddForm.userName" auto-complete="off" :placeholder="nowLangue.pleaseImport+nowLangue.loginAccount"></el-input>
	            </el-form-item>
                <!--密　　码-->
	            <el-form-item :label="nowLangue.password" prop="password" :rules="[{ required: true, message: nowLangue.required},{ min: 1, message: nowLangue.greaterThan1},{ max: 20, message: nowLangue.lessThan20},{ validator: validatePass, trigger: 'blur' }]">
	                <el-input size="mini" type="password" onfocus="this.type='password'" v-model.trim="bpStaffAddForm.password" auto-complete="off" :placeholder="nowLangue.pleaseImport+nowLangue.password"></el-input>
	            </el-form-item>
                <!--确认密码-->
	            <el-form-item :label="nowLangue.confirmPassword" prop="passwordRepeat"  :rules="[{ required: true, message: nowLangue.required},{ min: 1, message: nowLangue.greaterThan1},{ max: 20, message: nowLangue.lessThan20},{ validator: validatePass2, trigger: 'blur' }]">
	                <el-input size="mini" type="password" onfocus="this.type='password'" v-model.trim="bpStaffAddForm.passwordRepeat" auto-complete="off" :placeholder="nowLangue.pleaseImport+nowLangue.confirmPassword"></el-input>
	            </el-form-item>
                <!--联系电话-->
	            <el-form-item :label="nowLangue.contactNumber" prop="telephone" :rules="[{ required: true, message: nowLangue.required},{ validator: checkTelephone, trigger: 'blur' }]">
	                <el-input size="mini" v-model.trim="bpStaffAddForm.telephone" auto-complete="off" :placeholder="nowLangue.pleaseImport+nowLangue.contactNumber"></el-input>
	            </el-form-item>
                <!--邮　　箱-->
				<el-form-item :label="nowLangue.email" prop="email" :rules="[{ required: true, message: nowLangue.required},{ validator: checkEmail, trigger: 'blur' }]">
					<el-input size="mini" v-model.trim="bpStaffAddForm.email" auto-complete="off" :placeholder="nowLangue.pleaseImport+nowLangue.email"></el-input>
	            </el-form-item>
                <!--所属法人-->
	            <el-form-item :label="nowLangue.LegalUnderItsJurisdiction" prop="legalPersonId" class="code-input" :rules="[{ required: true, message: nowLangue.required}]">
                    <el-select size="mini" v-model.trim="bpStaffAddForm.legalPersonId" @change="searchProvider(bpStaffAddForm.legalPersonId, bpStaffAddForm, true)" :placeholder="nowLangue.pleaseSelect">
                        <el-option v-for="(lpOption,index) in bpStaffAddForm.legalPersonOptions" :key="index" :value="'' + lpOption.id" :label="lpOption.legalPersonName" :title="lpOption.legalPersonName">
                            <!--  
                            <span style="float: left">{{ lpOption.legalPersonName }}</span>
                            <span style="float: right; color: #8492a6; font-size: 13px">{{ lpOption.legalPersonCode }}</span>
                            -->
                        </el-option>
                    </el-select>
	            </el-form-item>
                <!--　法人代码-->
                <el-form-item :label="nowLangue.legalCode" class="code-input" >
                    <el-select size="mini" disabled v-model="bpStaffAddForm.legalPersonId" :placeholder="nowLangue.pleaseSelect">
                        <el-option v-for="(lpOption,index) in bpStaffAddForm.legalPersonOptions" :key="index" :value="'' + lpOption.id" :label="lpOption.legalPersonCode">
                            <span>{{ lpOption.legalPersonCode }}</span>
                        </el-option>
                    </el-select>
	            </el-form-item>
                <!--公司名称-->
	            <el-form-item :label="nowLangue.corporateName" class="inputWidth100 code-input" prop="providerId"  :rules="[{ required: true, message: nowLangue.required}]">
                    <el-select size="mini" v-model="bpStaffAddForm.providerId" :placeholder="nowLangue.pleaseSelect">
                        <el-option v-for="(providerOption,index) in bpStaffAddForm.providerOptions" :key="index" :value="'' + providerOption.id" :label="providerOption.partnerName" :title="providerOption.partnerName">
                        </el-option>
                    </el-select>
	            </el-form-item>
                <!--　公司代码-->
                <el-form-item :label="nowLangue.corporateCode" >
                    <el-select size="mini" disabled v-model="bpStaffAddForm.providerId" :placeholder="nowLangue.pleaseSelect">
                        <el-option v-for="(providerOption,index) in bpStaffAddForm.providerOptions" :key="index" :value="'' + providerOption.id" :label="providerOption.partnerCode">
                        	<span>{{providerOption.partnerCode}}</span>
                        </el-option>
                    </el-select>
	            </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <!--返回-->
                <el-button class="bolder outsideBtnBS" @click="dialogbpStaffAddFormVisible = false" size="mini" v-text="nowLangue.return"></el-button>
                <!--保存-->
	            <el-button class="bolder outsideBtnBS" @click="addbpStaff('bpStaffAddForm')" size="mini" type="danger" v-text="nowLangue.save" :disabled="addSaveDisabled"></el-button>
            </div>
        </el-dialog>

        <!--修改业务合作人员-->
        <el-dialog :title="nowLangue.update+nowLangue.businessCooperationPersonnel" :visible.sync="dialogbpStaffEditFormVisible" id="editMask" size="small" :lock-scroll="false">
            <el-form :model="bpStaffEditForm" ref="bpStaffEditForm"  :inline="true"  class="demo-form-inline label-minW110">
                <!--姓　　名-->
                <el-form-item :label="nowLangue.fullName" prop="personName">
	                <el-input size="mini" disabled v-model="bpStaffEditForm.personName" auto-complete="off"></el-input>
	            </el-form-item>
                <!--登录账户-->
	            <el-form-item :label="nowLangue.loginAccount" prop="userName">
	                <el-input size="mini" disabled v-model="bpStaffEditForm.userName" auto-complete="off"></el-input>
	            </el-form-item>
                <!--联系电话-->
	            <el-form-item :label="nowLangue.contactNumber" prop="telephone"  :rules="[{ required: true, message: nowLangue.required},{ validator: checkTelephone, trigger: 'blur' }]">
	                <el-input size="mini" v-model.trim="bpStaffEditForm.telephone" auto-complete="off" :placeholder="nowLangue.pleaseImport+nowLangue.contactNumber"></el-input>
	            </el-form-item>
                <!--邮　　箱-->
	            <el-form-item :label="nowLangue.email" prop="email" :rules="[{ required: true, message: nowLangue.required},{ validator: checkEmail, trigger: 'blur' }]">
	                <el-input size="mini" v-model.trim="bpStaffEditForm.email" auto-complete="off" :placeholder="nowLangue.pleaseImport+nowLangue.email"></el-input>
	            </el-form-item>
                <!--所属法人-->
	        	<el-form-item :label="nowLangue.LegalUnderItsJurisdiction" prop="legalPersonId" :rules="[{ required: true, message: nowLangue.required}]">
	                <el-select size="mini" v-model="bpStaffEditForm.legalPersonId" @change="searchProvider(bpStaffEditForm.legalPersonId, bpStaffEditForm, true)" :placeholder="nowLangue.pleaseSelect">
	                    <el-option v-for="(lpOption,index) in bpStaffEditForm.legalPersonOptions" :key="index" :value="'' + lpOption.id" :label="lpOption.legalPersonName">
	                    	<span style="float: left">{{ lpOption.legalPersonName }}</span>
							<span style="float: right; color: #8492a6; font-size: 13px">{{ lpOption.legalPersonCode }}</span>
	                    </el-option>
	                </el-select>
	            </el-form-item>
                <!--法人代码-->
                <el-form-item :label="nowLangue.legalCode">
	                <el-select size="mini" disabled v-model="bpStaffEditForm.legalPersonId" :placeholder="nowLangue.pleaseSelect">
	                    <el-option v-for="(lpOption,index) in bpStaffEditForm.legalPersonOptions" :key="index" :value="'' + lpOption.id" :label="lpOption.legalPersonCode">
	                    	<span>{{ lpOption.legalPersonCode }}</span>
	                    </el-option>
	                </el-select>
	            </el-form-item>
                <!--公司名称-->
	            <el-form-item :label="nowLangue.corporateName" prop="providerId" :rules="[{ required: true, message: nowLangue.required}]">
	                <el-select size="mini" v-model="bpStaffEditForm.providerId" :placeholder="nowLangue.pleaseSelect">
	                    <el-option v-for="(providerOption,index) in bpStaffEditForm.providerOptions" :key="index" :value="'' + providerOption.id" :label="providerOption.partnerName">
	                    	<span style="float: left">{{providerOption.partnerName}}</span>
							<span style="float: right; color: #8492a6; font-size: 13px">{{providerOption.partnerCode}}</span>
	                    </el-option>
	                </el-select>
	            </el-form-item>
                <!--公司代码-->
                <el-form-item :label="nowLangue.corporateCode">
	                <el-select size="mini" disabled v-model="bpStaffEditForm.providerId" :placeholder="nowLangue.pleaseSelect">
	                    <el-option v-for="(providerOption,index) in bpStaffEditForm.providerOptions" :key="index" :value="'' + providerOption.id" :label="providerOption.partnerCode">
	                    	<span>{{providerOption.partnerCode}}</span>
	                    </el-option>
	                </el-select>
	            </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <!--返回-->
                <el-button class="bolder outsideBtnBS" @click="dialogbpStaffEditFormVisible = false" size="mini" v-text="nowLangue.return"></el-button>
                <!--保存-->
	            <el-button class="bolder outsideBtnBS" @click="editbpStaff('bpStaffEditForm')" size="mini" type="danger" v-text="nowLangue.save" :disabled="updateSaveDisabled"></el-button>
            </div>

        </el-dialog>
        <!--重置密码的弹框-->
        <!--重置密码-->
        <el-dialog :title="nowLangue.resetPassword" :visible.sync="resetPasswordFormVisible" size="tiny" :lock-scroll="false">
            <el-form :model="bpStaffEditForm" ref="bpStaffEditForm"  :inline="true"  class="demo-form-inline label-minW110">
                <!--姓名-->
                <el-form-item :label="nowLangue.fullName">
                    <el-input size="mini" disabled v-model="bpStaffEditForm.personName" auto-complete="off"></el-input>
                </el-form-item>
                <!--登录账户-->
                <el-form-item :label="nowLangue.loginAccount">
                    <el-input size="mini"  disabled v-model="bpStaffEditForm.userName"
                              auto-complete="off"></el-input>
                </el-form-item>
                <!--密码-->
                <el-form-item :label="nowLangue.password" prop="resetPassword" :rules="[{ required: true, message: nowLangue.required},{ min: 1, message: nowLangue.greaterThan1},{ max: 20, message: nowLangue.lessThan20},{ validator: resetValidatePass, trigger: 'blur' }]">
                    <el-input size="mini" type="password" onfocus="this.type='password'" v-model.trim="bpStaffEditForm.resetPassword" auto-complete="off" :placeholder="nowLangue.pleaseImport+nowLangue.password"></el-input>
                </el-form-item>
                <!--确认密码-->
                <el-form-item :label="nowLangue.confirmPassword" prop="resetPasswordRepeat" :rules="[{ required: true, message: nowLangue.required},{ min: 1, message: nowLangue.greaterThan1},{ max: 20, message: nowLangue.lessThan20},{ validator: resetValidatePass2, trigger: 'blur' }]">
                    <el-input size="mini" type="password" onfocus="this.type='password'" v-model.trim="bpStaffEditForm.resetPasswordRepeat" auto-complete="off" :placeholder="nowLangue.pleaseImport+nowLangue.confirmPassword"></el-input>
                </el-form-item>
                <!--公司名称-->
                <el-form-item :label="nowLangue.corporateName">
                    <el-input size="mini"  disabled v-model="bpStaffEditForm.providerName" auto-complete="off"></el-input>
                </el-form-item>
                <!--公司代码-->
                <el-form-item :label="nowLangue.corporateCode">
                    <el-input size="mini"  disabled v-model="bpStaffEditForm.providerCode" auto-complete="off"></el-input>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <!--返 回-->
                <el-button class="bolder outsideBtnBS" size="mini" @click="resetPasswordFormVisible = false" v-text="nowLangue.return"></el-button>
                <!--保 存-->
                <el-button class="bolder outsideBtnBS" size="mini" type="danger" @click="handleResetPassword('bpStaffEditForm')" v-text="nowLangue.save" :disabled="resetPSaveDisabled"></el-button>
            </div>
        </el-dialog>
	</div>
</template>

<script>
import Vue from 'vue'
export default  {
    data() {
        var _this=this;
        //验证数据是否合法
        //效验登录账号
        var checkUserName = (rule, value, callback) => {

            if (!value) {
                var tip1=_this.languageType=="zh"?'登录账号不能为空':'Logon account cannot be empty';
                return callback(new Error(tip1));
            }
            setTimeout(() => {
                var re =  /^[0-9a-zA-Z]*$/g;  //判断字符串是否为数字和字母组合
            if (!re.test(value)){
                var tip2=_this.languageType=="zh"?'请输入数字或字母组合':'Please enter a combination of numbers or letters';
                callback(new Error(tip2));
            } else {
                //判断是否已经存在
                var id = _this.bpStaffAddForm.userId==null?"":_this.bpStaffAddForm.userId;
                var tmp = {userId:id,userName:value};
                $.ajax({
                    type: 'POST',
                    async:false,
                    url: _this.metadata_service+"partner/addIfExist",
                    cache: false,
                    data:JSON.stringify(tmp),
                    dataType:'JSON',
                    contentType: "application/json;charset=utf-8",
                    success: function (data) {
                        //存在时候给友好提示
                        if (!(data.success)) {
                            callback(new Error(data.errorMessage));
                        }else{
                            callback();
                        }
                    }
                });
                callback();
            }
        }, 1000);
        };
        //效验新增密码是否正确
        var validatePass = (rule, value, callback) => {
            if (!value) {
                var tip3=_this.languageType=="zh"?'请输入密码':'Please input a password';
                callback(new Error(tip3));
            } else {
                var re =  /^[0-9a-zA-Z]*$/g;  //判断字符串是否为数字和字母组合
                if (!re.test(value)){
                    var tip4=_this.languageType=="zh"?'请输入数字或字母组合':'Please enter a combination of numbers or letters';
                    callback(new Error(tip4));
                }else{
                    if (this.bpStaffAddForm.passwordRepeat !== '') {
                        this.$refs.bpStaffAddForm.validateField('passwordRepeat');
                    }
                    callback();
                }
            }
        };
        //判断是否与上一次密码一致
        var validatePass2 = (rule, value, callback) => {
            if (!value) {
                var tip5=_this.languageType=="zh"?'请再次输入密码':'Please enter your password again';
                callback(new Error(tip5));
            } else if (value !== this.bpStaffAddForm.password) {
                var tip6=_this.languageType=="zh"?'两次输入密码不一致':'The password for the two time is inconsistent';
                callback(new Error(tip6));
            } else {
                callback();
            }
        };
        //效验重置密码>密码是否正确
        var resetValidatePass = (rule, value, callback) => {
            if (!value) {
                var tip7=_this.languageType=="zh"?'请输入密码':'Please input a password';
                callback(new Error(tip7));
            } else {
                var re =  /^[0-9a-zA-Z]*$/g;  //判断字符串是否为数字和字母组合
                if (!re.test(value)){
                    var tip8=_this.languageType=="zh"?'请输入数字或字母组合':'Please enter a combination of numbers or letters';
                    callback(new Error(tip8));
                }else{
                    if (this.bpStaffEditForm.resetPasswordRepeat !== '') {
                        this.$refs.bpStaffEditForm.validateField('resetPasswordRepeat');
                    }
                    callback();
                }
            }
        };
        //效验重置密码>判断是否与上一次密码一致
        var resetValidatePass2 = (rule, value, callback) => {
            if (!value) {
                var tip9=_this.languageType=="zh"?'请再次输入密码':'Please enter your password again';
                callback(new Error(tip9));
            } else if (value !== this.bpStaffEditForm.resetPassword) {
                var tip10=_this.languageType=="zh"?'两次输入密码不一致':'The password for the two time is inconsistent';
                callback(new Error(tip10));
            } else {
                callback();
            }
        };
        //判断手机号是否正确
        var checkTelephone = (rule, value, callback) => {

            if (!value) {
                var tip11=_this.languageType=="zh"?'联系电话不能为空':'The telephone number cannot be empty';
                return callback(new Error(tip11));
            }
            //var re =  /^[0-9]*$/g;
            //11位手机号码或者1-4位分区号或者7-8位直播号码
            var re =  /((\d{11})|^((\d{7,8})|(\d{4}|\d{3})-(\d{7,8})|(\d{4}|\d{3})-(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1})|(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1}))$)/;
            if (!re.test(value)){
                var tip12=_this.languageType=="zh"?'请输入正确的电话号码':'Please enter the correct phone number';
                callback(new Error(tip12));
            }else {
                callback();
            }
        };
        //效验邮箱是否正确
        var checkEmail = (rule, value, callback) => {

            if (!value) {
                var tip=_this.languageType=="zh"?'邮箱不能为空':'Mailbox cannot be empty';
                return callback(new Error(tip));
            }
            var re =   /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/;  //判断字符串是否为数字和字母组合
            if (!re.test(value)){
                var tip=_this.languageType=="zh"?'请输入正确的邮箱地址':'Please enter the correct email address';
                callback(new Error(tip));
            }else {
                callback();
            }
        };
    	return {
            nowLangue:{},
            checkUserName:checkUserName,  //校验登录账号
            validatePass:validatePass,  //校验新增密码是否正确
            validatePass2:validatePass2,  //判断是否与一次密码一致
            resetValidatePass:resetValidatePass,   //校验重置密码>密码是否正确
            resetValidatePass2:resetValidatePass2,  //效验重置密码>判断是否与上一次密码一致
            checkTelephone:checkTelephone,   // 判断手机号是否正确
            checkEmail:checkEmail,    // 校验邮箱是否正确
	        bpForm: {
	        	login : "",
	        	name : "",
	        	state : '',
	        	vendorName : "",
	        	vendorCode : "",
	        	legalPersonOptions : {},
	        	stateOptions: [{value: true, label: "启用"},{value: false, label: "禁用"}]
	        },
	        isPaging:false,
            pageIndex:1,    //当前页（必传）
            pageSize :10,   //每页多少条
            currentPage3:3,    //当前显示3页
            
            totalNumber: 10,     //总条数
            totalPage:1,    //总页数
            loading:false,
	        bpList: [],
	        bpStaffAddForm: {
                userId:"",
                personName:"",
                userName:"",
                password:"",
	        	legalPersonId : "",
                legalPersonName:"",
                legalPersonCode:"",
                legalPersonOptions:[],
	        	providerId : "",
                providerName:"",
                providerCode:"",
                providerOptions:[],
                email:"",
                telephone:"",
                enabled:"",
                status:""
	        	// providerOptions: []
	        },
	        bpStaffEditForm: {
                userId:"",
	        	legalPersonId : "",
	        	providerId : "",
	        	providerOptions: []
	        },

	        dialogbpStaffAddFormVisible: false,
	        dialogbpStaffEditFormVisible: false,
            //重置密码弹窗静默状态为关闭
            resetPasswordFormVisible: false,
            //权限
            powerFlag1:false,
            powerFlag2:false,
            //查询禁用
            selectDisabled:false,
            statusDisabled:false,     //状态操作按钮禁用
            addSaveDisabled:false,    // 新增业务合作人员的保存操作按钮禁用
            updateSaveDisabled:false,  //修改业务合作人员的保存操作按钮禁用
            resetPSaveDisabled:false // 重置密码的保存操作按钮禁用
	        
    	};
    },
    created:function(){
        var _this=this;
        _this.languageType=="zh"?_this.nowLangue=_this.language.zh:_this.nowLangue=_this.language.en;
    },
    computed:{
        powerData(){
            return this.$store.state.powerData;
        },
        languageType(){
            return this.$store.state.languageType;
        }
    },
    watch:{
        languageType(){
            var _this=this;
            _this.languageType=="zh"?_this.nowLangue=_this.language.zh:_this.nowLangue=_this.language.en;
        },
        powerData(){
            var _this = this;
            for(var i=0;i<_this.powerData.length;i++){
                if(_this.powerData[i]=="ROLE_security_businessCooperationPersonnel_modifyUser"){
                    //业务合作人员新增及修改人员信息权限
                    _this.powerFlag1=true;
                }
                if(_this.powerData[i]=="ROLE_security_businessCooperationPersonnel_resetPassword"){
                    //业务合作人员重置密码权限
                    _this.powerFlag2=true;
                }
            }
        }
    },
    mounted: function () {
      var _this = this;
        // //ajax前后查询按钮禁用
        // $(".selectAll").ajaxStart(function(){
        //     _this.selectDisabled=true;
        // });
        // $(".selectAll").ajaxStop(function(){
        //     _this.selectDisabled=false;
        // });
        //判断权限
        for(var i=0;i<_this.powerData.length;i++){
            if(_this.powerData[i]=="ROLE_security_businessCooperationPersonnel_modifyUser"){
                //业务合作人员新增及修改人员信息权限
                _this.powerFlag1=true;
            }
            if(_this.powerData[i]=="ROLE_security_businessCooperationPersonnel_resetPassword"){
                //业务合作人员重置密码权限
                _this.powerFlag2=true;
            }
        }
        _this.handleQuery(_this.pageIndex, _this.pageSize);
    },
    methods: {

        // 查询
        handleQuery(pageIndex,pageSize){
            var _this=this;
            _this.loading=true;
            var tmp = {
            	personName : _this.bpForm.name,
            	userName : _this.bpForm.login,
            	state : _this.bpForm.state,
            	providerName : _this.bpForm.vendorName,
            	providerCode : _this.bpForm.vendorCode,
            	enabled : _this.bpForm.state,
            	pageIndex : pageIndex,
            	pageSize : pageSize
            };
            _this.selectDisabled=true;
            $.ajax({
                type: 'POST',
                url: _this.metadata_service + "partner/search",
                cache: false,
                data:JSON.stringify(tmp),
                dataType:'JSON',
                contentType: "application/json;charset=utf-8",     //*****
                success: function (data) {
                    if (data.success) {
                        _this.loading=false;
                        _this.bpList = data.data.dataList;
                        _this.isPaging=true;      //显示分页
                        _this.totalNumber=data.data.totalNumber;    //总条数
                        _this.totalPage=data.data.totalPage;    //总页数
                    } else {
                        _this.common.errorTip(data.errorMessage);
                    }
                    _this.selectDisabled=false;
                }
            });            
        },
        showAddStaffForm(){
    		var _this = this;
            //清空新增时绑定数据
            if(this.$refs['bpStaffAddForm']){
                this.$refs['bpStaffAddForm'].resetFields();
            }
    		$.ajax({
                type: 'GET',
                //url: _this.metadata_service + "legalPerson/listAllLegalPerson",
                url: _this.metadata_service + "legalPerson/listEnableEgalPerson",
                cache: false,
                dataType:'JSON',
                contentType: "application/json;charset=utf-8",     //*****
                success: function (data) {
                    if (data.success) {
                        _this.bpStaffAddForm.legalPersonOptions = data.data;
                	 	_this.dialogbpStaffAddFormVisible = true;
                    } else {
                        // console.log(data.errorMessage);
                        _this.common.errorTip(data.errorMessage);
                    }
                }
            });                
        },
        searchProvider(legalPersonId, targetForm, shallClear){
			var _this = this;
			if(shallClear){
				targetForm.providerId='';
			}
    		$.ajax({
                type: 'GET',
                url: _this.metadata_service + "partner/queryByLegalPerson",
                cache: false,
                data:{"legalPersonId": legalPersonId},
                success: function (data) {
                	if(!data.errorCode){
                		targetForm.providerOptions = data.data;
                	}
                }
            });
			
                
        },

        //add
        addbpStaff(addingPerson){
            var _this = this;
            this.$refs[addingPerson].validate((valid) => {
                if (valid) {
                     var tmp={userId:_this.bpStaffAddForm.userId,personName:_this.bpStaffAddForm.personName,userName:_this.bpStaffAddForm.userName,password:_this.bpStaffAddForm.password,legalPersonId:_this.bpStaffAddForm.legalPersonId,providerId:_this.bpStaffAddForm.providerId,email:_this.bpStaffAddForm.email,telephone:_this.bpStaffAddForm.telephone};
                     _this.addSaveDisabled=true;
                    $.ajax({
                        type: 'POST',
                        url: _this.metadata_service + "partner/add",
                        cache: false,
                        data: JSON.stringify(tmp),
                        dataType:'JSON',
                        contentType: "application/json;charset=utf-8",
                        success: function (data) {
                            if(!data.errorCode){
                                _this.dialogbpStaffAddFormVisible = false;
                                var success=_this.languageType=="zh"?'新增成功！':'Create successfully!';
                                _this.common.successTip(success);
                                _this.handleQuery(_this.pageIndex, _this.pageSize);
                            }else{
                                _this.common.errorTip(data.errorMessage);
                            }
                            _this.addSaveDisabled=false;
                        }
                    });

                } else {
                    var  err=_this.common.formErrorInfo();
                    _this.common.errorTip(err);
                    return false;
                 }
            });
        },
        //修改
        shoEditStaffForm(bpPerson){
            var _this = this;
            //清空新增时绑定数据
            if(this.$refs['bpStaffEditForm']){
                this.$refs['bpStaffEditForm'].resetFields();
            }
            _this.bpStaffEditForm = Vue.util.extend(_this.bpStaffEditForm, bpPerson);
            /*_this.bpStaffEditForm.legalPersonId = "" + _this.bpStaffEditForm.legalPersonId;
            _this.bpStaffEditForm.providerId = "" + _this.bpStaffEditForm.providerId;*/
            /*_this.bpStaffEditForm.legalPersonOptions = [];
            _this.bpStaffEditForm.providerOptions = [];*/
            //获取法人
            $.ajax({
                type: 'GET',
                url: _this.metadata_service + "/partner/modifyView?userId="+bpPerson.userId,
                cache: false,
                dataType:'JSON',
                contentType: "application/json;charset=utf-8",     //*****
                success: function (data) {
                    if(data.success){
                        _this.bpStaffEditForm.legalPersonId='' + data.data.legalPersonId;
                        _this.bpStaffEditForm.providerId='' + data.data.providerId;
                       _this.getLegalPersonList();//获取法人列表
                    }else {
                        _this.common.errorTip(data.errorMessage);
                    }
                }
            });

                
        },
        //获取法人列表
        getLegalPersonList(){
            var _this=this;
            $.ajax({
                type: 'GET',
                url: _this.metadata_service + "legalPerson/listEnableEgalPerson",
                cache: false,
                dataType:'JSON',
                contentType: "application/json;charset=utf-8",     //*****
                success: function (data) {
                    if(data.success){
                        _this.bpStaffEditForm.legalPersonOptions = data.data; 
                        _this.searchProvider(_this.bpStaffEditForm.legalPersonId, _this.bpStaffEditForm, false);
                        _this.dialogbpStaffEditFormVisible = true;
                    }else {
                        _this.common.errorTip(data.errorMessage);
                    }
                }
            });
        },
        //重置密码点击事件
        resetPassword(bpPerson){
            var _this = this;
            //清空新增时绑定数据
            if(this.$refs['bpStaffEditForm']){
                this.$refs['bpStaffEditForm'].resetFields();
            }
            _this.bpStaffEditForm = Vue.util.extend(_this.bpStaffEditForm, bpPerson);
            _this.bpStaffEditForm.legalPersonOptions = [];
            _this.bpStaffEditForm.providerOptions = [];
            // console.log('before ajax  shoEditStaffForm');
            // console.log(_this.bpStaffEditForm);
    		$.ajax({
                type: 'GET',
                url: _this.metadata_service + "legalPerson/listEnableEgalPerson",
                cache: false,
                dataType:'JSON',
                contentType: "application/json;charset=utf-8",     //*****
                success: function (data) {
                	if(data.success){
                		// console.log('yes  shoEditStaffForm');
                        // console.log(_this.bpStaffEditForm)
                		_this.bpStaffEditForm.legalPersonOptions = data.data;
                		// _this.searchProvider(_this.bpStaffEditForm.legalPersonId, _this.bpStaffEditForm, false);
                		_this.resetPasswordFormVisible = true;
                	}else {
                        _this.common.errorTip(data.errorMessage);
                	}


                }
            });

        },
        //修改保存
        editbpStaff(editingbpStuff){
            var _this = this;  
            _this.$refs[editingbpStuff].validate((valid) => {
                if (valid) {
                    _this.updateSaveDisabled=true;
                    $.ajax({
                        type: 'POST',
                        url: _this.metadata_service + "partner/update",
                        cache: false,
                        data: JSON.stringify(_this.bpStaffEditForm),
                        dataType:'JSON',
                        contentType: "application/json;charset=utf-8",     //*****
                        success: function (data) {
                            if(data.success){
                                _this.dialogbpStaffEditFormVisible = false;
                                var success=_this.languageType=="zh"?'修改成功！':'Update successfully!';
                                _this.common.successTip(success);
                                _this.handleQuery(_this.pageIndex, _this.pageSize);
                            }else{
                                _this.common.errorTip(data.errorMessage);
                            }
                            _this.updateSaveDisabled=false;
                        }
                    });
                } else {
                    var  err=_this.common.formErrorInfo();
                    _this.common.errorTip(err);
                    return false;
                 }
             });
        },

        //点击页码分页查询点击事件
        handleCurrentChange(val) {
            // console.log(`当前页: ${val}`);
            var _this = this;
            _this.pageIndex=val;
            _this.handleQuery(_this.pageIndex, _this.pageSize);
        },

		//更改状态
        updatestatus(id, status) {
            var _this = this;
            var tmp = {userId: id, enabled: status};
            _this.statusDisabled=true;
            $.ajax({
                type: 'POST',
                url: _this.metadata_service + "legalPerson/updateStaffStatus",
                cache: false,
                data: JSON.stringify(tmp),
                dataType: 'JSON',
                contentType: "application/json;charset=utf-8",
                success: function (data) {
                    if (data.success) {
                        var success=_this.languageType=="zh"?'提交成功！':'Submit successfully!';
                        _this.common.successTip(success);
                        _this.handleQuery(_this.pageIndex, _this.pageSize);
                    } else{
                        _this.common.errorTip(data.errorMessage);
                    }
                    _this.statusDisabled=false; 
                }
            });
        },
        handleSizeChange(val) {
            // console.log(`每页 ${val} 条`);
            var _this = this;
            _this.pageSize=val;
            _this.handleQuery(_this.pageIndex, _this.pageSize);
        },

        //启用按钮点击事件
        handleOpen(index, row){
            var _this = this;
            _this.updatestatus(row.userId, true);
        },
        //禁用按钮点击事件
        handleDisable(index, row){
            var _this = this;
            _this.updatestatus(row.userId, false);
        },
        //重置密码保存点击事件
        handleResetPassword(formName) {
            var _this = this;
            _this.$refs[formName].validate((valid) => {
                if (valid) {
                    var _this = this;
                    var tmp = {
                        id: _this.bpStaffEditForm.userId,
                        password: _this.bpStaffEditForm.resetPassword,
                    };
                    _this.resetPSaveDisabled=true;
                    $.ajax({
                        type: 'POST',
                        url: _this.metadata_service + "/legalPerson/resetPassword",
                        cache: false,
                        data: JSON.stringify(tmp),
                        dataType: 'JSON',
                        contentType: "application/json;charset=utf-8",
                        success: function (data) {
                            if (data.success) {
                                var success=_this.languageType=="zh"?'密码重置成功！':'Password reset succeeded!';
                                _this.common.successTip(success);
                                _this.handleQuery(_this.pageIndex, _this.pageSize);
                                _this.resetPasswordFormVisible=false
                            } else{
                                _this.common.errorTip(data.errorMessage);
                            }
                            _this.resetPSaveDisabled=false;   
                        }
                    });
                } else {
                    var  err=_this.common.formErrorInfo();
                    _this.common.errorTip(err);
                    return false;
                }
            });
        }
     }

  }

</script>